detect the need to sign the terms of service during login web flow v2
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 17 Feb 2025 08:14:05 +0000 (09:14 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 20 Feb 2025 11:00:54 +0000 (12:00 +0100)
should avoid being blocked by terms_of_service blocking WebDAV access

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
src/gui/connectionvalidator.cpp
src/gui/owncloudsetupwizard.cpp
src/gui/owncloudsetupwizard.h
src/gui/wizard/owncloudadvancedsetuppage.cpp
src/gui/wizard/owncloudadvancedsetuppage.h

index 31467ec3f4bf0306839a8fed2563f58b98267803..61ba6ee44751078a654229e6115a354ec40b7abb 100644 (file)
@@ -390,8 +390,8 @@ void TermsOfServiceChecker::slotServerTermsOfServiceRecieved(const QJsonDocument
     if (reply.object().contains("ocs")) {
         const auto needToSign = !reply.object().value("ocs").toObject().value("data").toObject().value("hasSigned").toBool(false);
         if (needToSign != _needToSign) {
-            qCInfo(lcConnectionValidator) << "_needToSign" << (_needToSign ? "need to sign" : "no need to sign");
             _needToSign = needToSign;
+            qCInfo(lcConnectionValidator) << "_needToSign" << (_needToSign ? "need to sign" : "no need to sign");
             emit needToSignChanged();
         }
     } else if (_needToSign) {
index 66282a067a2937ab92647521472ab8060a29dfdc..8f10fc52f65c4db7fc51bec82752fc989e23528f 100644 (file)
  * for more details.
  */
 
-#include <QAbstractButton>
-#include <QtCore>
-#include <QProcess>
-#include <QMessageBox>
-#include <QDesktopServices>
-#include <QApplication>
-
 #include "accessmanager.h"
 #include "account.h"
 #include "accountmanager.h"
 #include "sslerrordialog.h"
 #include "wizard/owncloudwizard.h"
 #include "wizard/owncloudwizardcommon.h"
+#include "connectionvalidator.h"
 
 #include "creds/credentialsfactory.h"
 #include "creds/abstractcredentials.h"
 #include "creds/dummycredentials.h"
 
+#ifdef BUILD_FILE_PROVIDER_MODULE
+#include "gui/macOS/fileprovider.h"
+#endif
+
+#include <QAbstractButton>
+#include <QtCore>
+#include <QProcess>
+#include <QMessageBox>
+#include <QDesktopServices>
+#include <QApplication>
+
 namespace OCC {
 
 OwncloudSetupWizard::OwncloudSetupWizard(QObject *parent)
@@ -377,7 +382,14 @@ void OwncloudSetupWizard::testOwnCloudConnect()
     job->setFollowRedirects(false);
     job->setProperties(QList<QByteArray>() << "getlastmodified");
     connect(job, &PropfindJob::result, _ocWizard, &OwncloudWizard::successfulStep);
-    connect(job, &PropfindJob::finishedWithError, this, &OwncloudSetupWizard::slotAuthError);
+    connect(job, &PropfindJob::finishedWithError, this, [this] (QNetworkReply *reply) {
+        if (reply && reply->error() == QNetworkReply::ContentAccessDenied) {
+            testTermsOfService();
+        } else {
+            slotAuthError();
+        }
+    });
+
     job->start();
 }
 
@@ -416,6 +428,9 @@ void OwncloudSetupWizard::slotAuthError()
 
         // A 404 is actually a success: we were authorized to know that the folder does
         // not exist. It will be created later...
+    } else if (reply->error() == QNetworkReply::ContentAccessDenied) {
+        testTermsOfService();
+        return;
     } else if (reply->error() == QNetworkReply::ContentNotFoundError) {
         _ocWizard->successfulStep();
         return;
@@ -473,6 +488,14 @@ bool OwncloudSetupWizard::checkDowngradeAdvised(QNetworkReply *reply)
     return true;
 }
 
+void OwncloudSetupWizard::testTermsOfService()
+{
+    _termsOfServiceChecker = new TermsOfServiceChecker{_ocWizard->account(), this};
+
+    connect(_termsOfServiceChecker, &TermsOfServiceChecker::done, this, &OwncloudSetupWizard::termsOfServiceChecked);
+    _termsOfServiceChecker->start();
+}
+
 void OwncloudSetupWizard::slotCreateLocalAndRemoteFolders(const QString &localFolder, const QString &remoteFolder)
 {
     qCInfo(lcWizard) << "Setup local sync folder for new oC connection " << localFolder;
@@ -726,6 +749,17 @@ void OwncloudSetupWizard::slotSkipFolderConfiguration()
     emit ownCloudWizardDone(QDialog::Accepted);
 }
 
+void OwncloudSetupWizard::termsOfServiceChecked()
+{
+    if (_termsOfServiceChecker && _termsOfServiceChecker->needToSign()) {
+        QDesktopServices::openUrl(_ocWizard->account()->url());
+    } else {
+        _ocWizard->successfulStep();
+        delete _termsOfServiceChecker;
+        _termsOfServiceChecker = nullptr;
+    }
+}
+
 AccountState *OwncloudSetupWizard::applyAccountChanges()
 {
     AccountPtr newAccount = _ocWizard->account();
index d7288ee6c8b77b2c9e2b7b82959fc911061ea9c9..fab85d9bbb4fe0a89868eb8d19de7e21e4ec583f 100644 (file)
@@ -30,6 +30,7 @@
 namespace OCC {
 
 class AccountState;
+class TermsOfServiceChecker;
 
 class OwncloudWizard;
 
@@ -69,6 +70,8 @@ private slots:
     void slotAssistantFinished(int);
     void slotSkipFolderConfiguration();
 
+    void termsOfServiceChecked();
+
 private:
     explicit OwncloudSetupWizard(QObject *parent = nullptr);
     ~OwncloudSetupWizard() override;
@@ -79,8 +82,10 @@ private:
     bool ensureStartFromScratch(const QString &localFolder);
     AccountState *applyAccountChanges();
     bool checkDowngradeAdvised(QNetworkReply *reply);
+    void testTermsOfService();
 
-    OwncloudWizard *_ocWizard;
+    TermsOfServiceChecker *_termsOfServiceChecker = nullptr;
+    OwncloudWizard *_ocWizard = nullptr;
     QString _initLocalFolder;
     QString _remoteFolder;
 };
index bb51e447438d0680061fed24a098353cd587450d..872f53f7f5d022067ee6f142281009d7ffb32a2f 100644 (file)
@@ -176,6 +176,7 @@ void OwncloudAdvancedSetupPage::initializePage()
     quotaJob->setProperties(QList<QByteArray>() << "http://owncloud.org/ns:size");
 
     connect(quotaJob, &PropfindJob::result, this, &OwncloudAdvancedSetupPage::slotQuotaRetrieved);
+    connect(quotaJob, &PropfindJob::finishedWithError, this, &OwncloudAdvancedSetupPage::slotQuotaRetrievedWithError);
     quotaJob->start();
 
 
@@ -547,6 +548,15 @@ void OwncloudAdvancedSetupPage::slotQuotaRetrieved(const QVariantMap &result)
     updateStatus();
 }
 
+void OwncloudAdvancedSetupPage::slotQuotaRetrievedWithError(QNetworkReply *reply)
+{
+    Q_UNUSED(reply)
+    _rSize = -1;
+    _ui.lSyncEverythingSizeLabel->setText({});
+
+    updateStatus();
+}
+
 qint64 OwncloudAdvancedSetupPage::availableLocalSpace() const
 {
     QString localDir = localFolder();
index 2c0f23bb42b37bff347232e06d39f30fb39e6167..d01ebe4d953d6798f390d08c7dc5069075872c2b 100644 (file)
@@ -23,6 +23,7 @@
 #include "elidedlabel.h"
 
 class QProgressIndicator;
+class QNetworkReply;
 
 namespace OCC {
 
@@ -63,6 +64,7 @@ private slots:
     void slotSelectiveSyncClicked();
     void slotVirtualFileSyncClicked();
     void slotQuotaRetrieved(const QVariantMap &result);
+    void slotQuotaRetrievedWithError(QNetworkReply *reply);
 
 private:
     void setRadioChecked(QRadioButton *radio);